package com.vueblog.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    private Object data;

    public static int code_ok = 200;
    public static int code_err_auth = 403;
    public static int code_err = 600;
    public static int code_err_biz = 601;
    public static int code_err_db = 602;

    public static Result build(int code, String msg, Object data) {
        Result result = new Result();
        result.code = code;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static Result success(Object data) {
        return build(code_ok, "success", data);
    }

    public static Result fail(int code, String msg) {
        return build(code, msg, null);
    }

    public static Result fail(String msg) {
        return fail(code_err, msg);
    }

}
